package net.kengo.volleyball.scheduler.data;

import java.text.*;
import java.util.*;

public class GameDay
{
   static SimpleDateFormat dayFormat  = new SimpleDateFormat("EEEE");
   static SimpleDateFormat dateFormat = new SimpleDateFormat("MMM d");

   private Map<Integer,Match> matches = new TreeMap<Integer,Match>();
   
   private String day  = null;
   private String date = null;

   public GameDay( GregorianCalendar date )
   {
      super();

      this.day  = dayFormat.format(date.getTime());
      this.date = dateFormat.format(date.getTime());
   }


   public int getNumMatches()
   {
      return matches.size();
   }
   
   public void addMatch( Integer matchNum, Match match )
   {
       matches.put(matchNum, match);
   }


   @Override
   public String toString()
   {
      String output = new String();

      int numMatches = getNumMatches();

      output += "          <TD ROWSPAN=" + numMatches + ">\n";
      output += "            <center>" + day + "</center>\n";
      output += "          </TD>\n";

      output += "          <TD ROWSPAN=" + numMatches + ">\n";
      output += "            <center>" + date + "</center>\n";
      output += "          </TD>\n";

      int count = 0;
      for( Match match : matches.values() )
      {
         if ( count != 0 ) output += "        <TR>\n";
         output += match.toString();
         output += "        </TR>\n";
         
         count++;
      }
      
      return output;
   }
}
